package com.ruoyi.project.mes.vehicleControl.manager;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.mes.vehicleControl.service.IGs11WeldingQueueIssueService;
import com.ruoyi.project.mes.vehicleControl.webService.gs11WeldingQueueIssue.BSMaterialsInfosService;
import com.ruoyi.project.mes.vehicleControl.webService.gs11WeldingQueueIssue.BSMaterialsInfosServiceserviceLocator;
import com.ruoyi.project.mes.vehicleControl.webService.gs11WeldingQueueIssue.VehicleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
import java.util.List;

/**
 * @author : kyc
 * @description : mes定时任务逻辑处理类
 * @date : 2021-03-29 14:49
 **/
@Component
public class MesTaskManager {

    @Autowired
    private IGs11WeldingQueueIssueService gs11WeldingQueueIssueService;

    /**
     * gs11焊装上线队列下发
     */
    public void gs11WeldingQueueIssue() {
        // 获取焊装未下发的数据
        List<VehicleInfo> list = gs11WeldingQueueIssueService.listWeldingQueueNotIssue();
        if (list.size() == 0) {
            return;
        }
        VehicleInfo[] vehicleInfos = list.toArray(new VehicleInfo[0]);
        try {
            // 调用webservice接口下发数据
            BSMaterialsInfosServiceserviceLocator locator = new BSMaterialsInfosServiceserviceLocator();
            BSMaterialsInfosService service = locator.getBSMaterialsInfosServicePort();
            String result = service.addVehicleASInfo(vehicleInfos, "0");
            System.out.println("gs11焊装上线队列下发成功");
            // 下发成功后修改数据状态
            if (Constants.OK.equals(result)){
                gs11WeldingQueueIssueService.updateWbsWeldingQueueIssueStatusBatch(list);
            }
        } catch (ServiceException | RemoteException e) {
            e.printStackTrace();
        }
    }
}
